package cn.stronglink.asset.module.basicdata.storeRoom.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.IdWorker;

import cn.stronglink.asset.model.StoreRoom;
import cn.stronglink.asset.module.basicdata.storeRoom.mapper.StoreRoomMapper;
import cn.stronglink.suite.core.util.WebUtil;

@Service
@Transactional(rollbackFor=Exception.class) 
public class StoreRoomService {

	@Autowired
	private StoreRoomMapper storeRoomMapper;

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page<StoreRoom> queryStoreRoom(Page<StoreRoom> page,Map<String, Object>  params) {
		page.setRecords(storeRoomMapper.queryStoreRoom(page,params));
		return page;	
	}
	
	public void removeStoreRoom(Long id){
		storeRoomMapper.removeStoreRoom(id);	
	}	

	public void insertStoreRoom(StoreRoom storeRoom) {
		if (storeRoom.getId() == null) {
			storeRoom.setId(IdWorker.getId());
			storeRoom.setCreateTime(new Date());
			storeRoom.setCreateBy(WebUtil.getCurrentUser());
			storeRoom.setType(2);
			storeRoomMapper.insertStoreRoom(storeRoom);		
		}else{
			storeRoom.setUpdateBy(WebUtil.getCurrentUser());
			storeRoom.setUpdateTime(new Date());
			storeRoomMapper.updateStoreRoom(storeRoom);
		}	
		
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<StoreRoom> queryRoomList() {
		return storeRoomMapper.queryRoomList();
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public int qryRoomCount() {
		return storeRoomMapper.qryRoomCount();
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Integer getRoomType(Long roomId) {
		return storeRoomMapper.getRoomType(roomId);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public int getIsUsedRoom(Long id) {
		return storeRoomMapper.getIsUsedRoom(id);
	}

	

	

}
